/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
# example client for position server with swig wrapped c++ library in python
import sys, time
#sys.path.append("../interfaces/common")
sys.path.append("../../GIMI")
#sys.path.append("../../../GIMI")
import SpeedCtrlClient as SCC
import gimi
if sys.argv.__len__() != 3:
	print "Usage: python %s clientName serverName"%sys.argv[0]
	sys.exit()
g = gimi.GIMI()
scc = SCC.CSpeedCtrlClient(g, 0)
print "connecting... ",
ret = g.connectToHubEx("localhost", 50002, sys.argv[1])
print SCC.GetErrorStr(ret)
print "set target... ",
if sys.argv[2].find(".") < 0:
	ret = scc.SetDefaultTarget(sys.argv[2])
else:
	print "with fancy name...",
	ret = scc.SetDefaultTarget(SCC.SMaCISL(sys.argv[2]))
if ret:
	print "target set"
else:
	print "failed to set target %s"%sys.argv[2]

print "open...",
ret = scc.Open()
print SCC.GetErrorStr(ret)
del ret
time.sleep(1.0) # got to sleep to wait for something to get ready to serve us
print "Go froward...",
ret = scc.SetSpeed(0.1, 0.0, 0.1)#lin, rot, acceleration
if ret:
	print "we are going"
	time.sleep(10.0)
else:
	print "Failed to move"
print "Go left...",
ret = scc.SetSpeed(0.0, 0.2, 0.1)#lin, rot, acceleration
if ret:
	print "we are going"
	time.sleep(10.0)
else:
	print "Failed to move"
	
print "stopping...",
scc.SetStop()
print "hopefully"
scc.Close()
time.sleep(0.1)#give some time to terminate before carbage collector messes up everything
print "bye bye"
